use {std::error::Error as StdError, std::fmt};
#[derive(Debug, Clone, PartialEq, serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum ClientError {
    ServerError(String),
}

impl StdError for ClientError {
    fn source(&self) -> Option<&(dyn StdError + 'static)> {
        use ClientError::*;

        match self {
            ServerError(_) => None,
        }
    }
}

impl fmt::Display for ClientError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        use ClientError::*;

        match self {
            ServerError(e) => write!(f, "API Server error: {}", e),
        }
    }
}

impl From<serde_json::Error> for ClientError {
    fn from(e: serde_json::Error) -> Self {
        Self::ServerError(e.to_string())
    }
}
